<template>
	<view>
		<text class="title">获得售货员{{h_title}}</text>
		<camera v-if="!face_image" device-position="front" flash="auto" @error="error" style="width: 480rpx; height: 480rpx; border-radius: 240rpx; margin: 0 auto;">
			<!-- <image class="icon" src="/static/face-image.png" mode="aspectFit" v-if="isFace == false"></image> -->
		</camera>
		<image class="icon" :src="face_image" v-if="face_image"></image>
		
		<view class="btn" @click="setFace">确认</view>
		<!-- <view class="btn" @click="order">结算订单</view> -->
		<!-- <text class="description">点击录入即代表您已阅读并同意《用户隐私协议》</text> -->
		
	</view>
</template>
<style lang="scss">
	
	page{
		background-color: #FFFFFF;
	}
	
	.title{
		font-size: 32rpx;
		text-align: center;
		display: block;
		margin: 100rpx 0;
	}
	
	.icon{
		display: block;
		margin: 0 auto;
		width: 480rpx; height: 480rpx;
		border-radius: 50%;
	}
	
	.btn{
		width: 594rpx;
		height: 92rpx;
		text-align: center;
		line-height: 92rpx;
		background-color: #2e8bf0;
		color: #FFFFFF;
		border-radius: 46rpx;
		margin: 50rpx auto;
	}
	
	.description{
		font-size: 24rpx;
		color: #666666;
		text-align: center;
		display: block;
	}
	
	.scan-img{
		opacity: 0.4;
		width: 100%;
		height:500upx;
	}
	
	.scan-text{
		font-size: 20px;
		text-align: center;
		line-height: 60upx;
	}
	
</style>
<script>
	let camera = uni.createCameraContext({
			takePhoto:{
				quality:"high"
			}
		})
	export default {
		data() {
			return {
				isFace:false,
				face_image:"",
				order_sn:"",
				h_title:"人脸信息"
			}
		},
		onLoad(options){
			this.h_title= uni.getStorageSync('storage_key')==1 ? "认证信息" : '人脸信息'
			this.order_sn = options.order_sn;
			const context = uni.createCameraContext();
			// this.$u.api.getUserInfo().then(res => {
			// 	this.face_image = res.data.face_image;
			// });
		},
		methods: {
			setFace(){
				uni.showLoading();
				const ctx = uni.createCameraContext();
				ctx.takePhoto({
					quality: 'high',
					success: (res) => {
						this.$u.api.uploadFile({
							url:'user/upload/one?app=saleface',
							filePath: res.tempImagePath,
							name: 'file',
							success:uploadRes => {
								if(uploadRes.code == 0){
									this.$u.toast(res.msg)
								}else{
									
									this.$u.http.get("order/order/update",{
										order_sn:this.order_sn,
										entity_id:uploadRes.data.entityId
									}).then(res => {
										uni.navigateTo({
											url:"/pages/order/confirm?order_sn=" + this.order_sn
										})
										this.face_image = uploadRes.data.preview_url;
									})
								}
							},
							complete:res => {
								uni.hideLoading();
							}
						});
					}
				});
				
			}
		}
	}
</script>

<style>

</style>
